package gecko.view.swing.PARAMETRES;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.sql.SQLException;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.TableColumn;

import gecko.model.Requete;
import gecko.view.IObservable;
import gecko.view.swing.VAdmin;

public class ParamFournisseur2 extends VAdmin implements IObservable {
	
    private static final long serialVersionUID = 1L;
    private JTable tableau;
	
	public ParamFournisseur2() throws SQLException {
		super(controleur, false);

		Requete requete= new Requete();
	    Object[][] donnees = requete.consulteFournisseur();

	    String[] entetes = {"N°du fournisseur","Nom du fournisseur", "Numero", "Rue", "CP", "Ville"};

	    tableau = new JTable(donnees, entetes);

	    // Deuxieme colonne de largeur 150px
	    tableau.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
	    
	    for (int i = 0; i < tableau.getColumnCount(); i++) {
			int vColIndex = i;
			TableColumn col = tableau.getColumnModel().getColumn(vColIndex);
			int width = 150;
			col.setPreferredWidth(width);
		}
	    
		// Creation des composants
		JLabel lParamService = new JLabel(new ImageIcon("images/menu/Titre/ParametreT-F_V.png"));
		
		JButton bAjout = new JButton(new ImageIcon("images/boutons/vert/Ajouter_V.png"));
		bAjout.setActionCommand("AJOUT_FOURNISSEUR");
		bAjout.addActionListener(controleur);
		bAjout.setBorder(null);
		bAjout.setBorderPainted(false);
		bAjout.setContentAreaFilled(false);

		JButton bModifier = new JButton(new ImageIcon("images/boutons/vert/Modifier_V.png"));
		bModifier.setActionCommand("MODIFICATION_FOURNISSEUR");
		bModifier.addActionListener(controleur);
		bModifier.setBorder(null);
		bModifier.setBorderPainted(false);
		bModifier.setContentAreaFilled(false);	
	        
		// Creation du conteneur << Libelle >> et ajout des composants
		JPanel pLib = new JPanel(new FlowLayout());
		pLib.add(lParamService);
		pLib.setBorder(BorderFactory.createEmptyBorder(50, 0, 0, 0));
		
		// Creation du conteneur << tab >> et ajout des composants
		JPanel pTab = new JPanel(new GridLayout(2,1));
		pTab.add(tableau.getTableHeader());
		pTab.add(tableau);
		
		JPanel pCenter = new JPanel(new FlowLayout());
		pCenter.add(pTab);
		pCenter.setBorder(BorderFactory.createEmptyBorder(100, 0, 0, 0));
		
		// Creation du conteneur << Button >> et ajout des composants
		JPanel pButton = new JPanel(new FlowLayout());
		pButton.add(bAjout);
		pButton.add(bModifier);	
		
		// Ajout de ce conteneur au conteneur de ma fenetre
		lCorps.add(pLib, BorderLayout.NORTH);
		lCorps.add(pCenter, BorderLayout.CENTER);
		lCorps.add(pButton, BorderLayout.SOUTH);		
		
	    // Assemblage de la fenetre
	    this.pack();

	    // Affichage de cette fenetre
	    //this.vuebase.place();
		

        this.setSize(1440, 900);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(true);

	}
}